(function () {
  var baseUrl = "http://zhouxiumin123.oschina.io/ipadmangareader";

  function init() {
    var AllLinks = document.querySelectorAll("head>link");
    for (var i = 0; i < AllLinks.length; ++i)
      document.head.removeChild(AllLinks[i]);
    document.body.style.cssText = "margin:0;padding:0;text-align:center;";
    document.body.innerHTML = "";
    var meta = document.createElement("meta");
    meta.name = "viewport";
    meta.content = "width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=no";
    document.head.appendChild(meta);
  }

  function hasNotLoaded() {
    return !document.getElementById("iPadReader");
  }

  function addStyle(href) {
    var linkTag = document.createElement("link");
    linkTag.href = baseUrl + href;
    linkTag.setAttribute('rel', 'stylesheet');
    linkTag.setAttribute('media', 'all');
    linkTag.setAttribute('type', 'text/css');
    document.head.appendChild(linkTag);
  }

  function addScript(id, src) {
    var a = document.createElement("script");
    a.setAttribute("type", "text/javascript");
    a.setAttribute("charset", "utf-8");
    a.src = baseUrl + src;
    a.id = id;
    document.body.appendChild(a);
  }

  function addIonicView() {
    var ion_app =document.createElement("ion-app");
    document.body.appendChild(ion_app);
  }
  function addFonts() {

  }

  function main() {
    if (hasNotLoaded()) {
      init();
      addStyle("/build/main.css");
      addIonicView();
      addScript("polyfills", "/build/polyfills.js");
      addScript("iPadReader", "/build/main.js");
    }
  }

  main();
})();
